package com.lyb.spzx.manager.controller;

import cn.hutool.http.server.HttpServerResponse;
import com.lyb.spzx.manager.service.CategoryService;
import com.lyb.spzx.model.entity.product.Category;
import com.lyb.spzx.model.vo.common.Result;
import com.lyb.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "商品分类")
@RestController
@RequestMapping("admin/product/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    @GetMapping("/findCategoryByid/{parentId}")
    public Result<List<Category>> findCategoryByParentId(@PathVariable Long parentId){
        List<Category> categories = categoryService.findCategoryById(parentId);
        return Result.build(categories, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "导出文件")
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response){
        categoryService.exportData(response);
    }

    @Operation(summary = "导入")
    @PostMapping("/importData")
    public Result importData(MultipartFile file){
        categoryService.importData(file);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
